class Solution:
    def maxScoreSightseeingPair(self, A: list) -> int:
        res = 0
        pos = 0
        for i in range(1, len(A)):
            res = max(res, A[pos] + pos + A[i] - i)
            if A[i] + i > A[pos] + pos:
                pos = i
        
        return res
